Repository navigation
Sentence trigger - #869
Sentence trigger#869contagon wants to merge 8 commits into
Conversation
|
Nice implementation! I still need more time for a full review. My first thought is to pass slots as named function arguments. That would be much more convenient. #From:
@sentence_trigger("turn on {name} in the {area}")
def voice_on(sentence, slots):
service.call("light", "turn_on", entity_id=f"light.{slots['name']}")
return f"Turned on {slots['name']} in the {slots['area']}"
#To:
@sentence_trigger("turn on {name} in the {area}")
def voice_on(sentence, name, area):
service.call("light", "turn_on", entity_id=f"light.{name}")
return f"Turned on {name} in the {area}"
Any objections? Edit: In my head, the legacy decorators and the new DM are already decoupled. I will try to speed up the work on removing the old subsystem. Alternatively, I can make a PR where DM is not tied to |
|
We keep doing things simultaneously! I just came to the same conclusion. So I think the options are,
@sentence_trigger("turn on {name} in the {area}")
def voice_on(sentence, name): # missing area!
service.call("light", "turn_on", entity_id=f"light.{name}")
return f"Turned on {name}"If all slots are included, this would work fine with the current
I definitely prefer either 2 or 3 as the long term solution, but am open to either option. |
|
I have a few spare tokens, and there can be no such thing as an unneeded review, so here's what Opus said: Reviewed at This is clean work, and the test file covers a lot: validators, apostrophes, positional and Six points below. 1. An exception or a cancellation makes the caller wait for the whole timeout
Without them, the future stays pending in three reachable cases:
In each case Your own test shows the cost: 2.
|
|
Thanks @ALERTua for putting it through. A few of those points need correcting.
On "not a valid option" — that's a shim for the transition period from |
|
Hi @contagon, sorry for the long gap. #870 has now been merged, so the new decorator subsystem no longer depends on the @sentence_trigger("turn on {name} in the {area}")
def voice_on(sentence, name, area):
...A function can omit slots it doesn't need, or use To get this ready to merge:
Thanks for your patience, and for developing a really useful feature! |
|
Awesome, I'll get right on making those edits. Since this was last reviewed, I hit a potential edge case that I wanted to get feedback on how you'd like implemented, @sentence_trigger("turn on {name} in the {area}")
@sentence_trigger("Something that doesn't involve a slot")
def voice_on(sentence, name, area):
...I would assume in this case we should just pass |
|
I'd keep it simple and avoid any special handling: just pass the slots that came out of the @sentence_trigger("turn on {name} in the {area}")
@sentence_trigger("Something that doesn't involve a slot")
def voice_on(sentence, name=None, area=None):
...This is plain Python semantics, with no implicit |
|
Now that #899 is merged, |
19d0da6 to
e28c06b
Compare
|
Updated against current master (b32fcfa):
I think that covers everything that was mentioned. Let me know if you see anything else that needs to be tweaked! |
craigbarratt
left a comment
There was a problem hiding this comment.
Thanks @contagon, this looks great, and building on RequestResponseDecorator made it much simpler. Besides the tests, I ran it end to end with the real conversation component: "turn on the kitchen please" calls the function with name="kitchen" and speaks its string response, and an exception or a None return gives "Done". The pins match what HA 2026.11's conversation component uses.
Two things before merging:
- Import
conversationthe way #930 now imports mqtt.homeassistant.components.conversation(which pulls in hassil and the intents) is imported inside the event loop, in the sentence validators and instart(). If pyscript loads before conversation, that can give the same blocking-import warning #930 just fixed for mqtt. pylint also flags both function-level imports (import-outside-toplevel), so the pre-commit check fails. Please:- add
"conversation"toafter_dependenciesinmanifest.json, so it loads first when it's set up; - import it with
await async_import_module(hass, ...). For the validators, that means importing it invalidate()before the schema runs.
- add
- Pass
context. Please add"context": user_input.contextto the function's arguments. The decorator manager then gives the function's actions a context whose parent is the conversation's, as it does for the other triggers and@service, so they're linked in the logbook. Right nowcontextisNone.
This is the first of two PRs for integrating pyscript with HA assist pipelines. It ties into the "exact matches" portion of the default HA assist pipeline. Should close #672.
This PR adds in
sentence_triggerthat (should) work near identically to the built-in sentence trigger. This includes return values being spoken, wildcards using {}, one of the following using (a|b|c), and optional words in []. I've been using this for ~week now and it's been working fairly flawless on basic cases.Let me know if there's anything that needs tweaking and as always I recommend giving it a shot first before merging. Next I hope to play with a
@intentdecorator that would register a method as an intent/tool for agents to call, similar to this integration.(Also shoutout to @dmamelin, the new decorator registry made this a breeze!)